package controllers;

import java.util.Date;
import java.util.List;

import play.modules.paginate.ValuePaginator;
import play.mvc.With;

import common.FBSecure;

import models.HitchhikerJourney;
import models.Journey;
import models.Message;
import models.User;

@With(FBSecure.class)
public class EditHitcJourney extends FBController {

	public static void edithitcjourneydetails(long id){
		
		setFbIdandName();

		User user = getUser();
		
		HitchhikerJourney hitcJourney = HitchhikerJourney.findById(id);
		
		render(user, hitcJourney);
	}
	
	public static void updatehitcjourneydetails(long id,  String departurestate,
			 String departuretownn, String departurestreet, Date departuredate, 
			 String departurehour,  String arrivestate,
			 String arrivetownn,  String arrivestreet,  String journeynotes, 
			 boolean priceshare ){
		

		setFbIdandName();

		User user = getUser();
		
		HitchhikerJourney hitcJourney = HitchhikerJourney.findById(id);
				
		hitcJourney.updateHitc(departurestate, departuretownn, departurestreet, departuredate,  departurehour, arrivestate,
			arrivetownn, arrivestreet,  journeynotes, priceshare);
		
		
		renderTemplate("HitcJourneyDetails/hitcjourneydetails.html", user, hitcJourney);

	}
	
	public static void deletehitcjourney(long id){
		
		setFbIdandName();

		User user = getUser();
		
		HitchhikerJourney journey = HitchhikerJourney.findById(id);
				
		journey.delete();
		
		User profileUser = getUser();
		
		List<Journey> journeyList = profileUser.getJourneyList();
		
		ValuePaginator paginator = new ValuePaginator(journeyList);
		paginator.setPageSize(5);
		
		renderTemplate("Profile/profile.html", user, profileUser, journeyList, paginator);
		
	}
	
}
